package com.vict.util;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;

public class DbUtils {

    public static DataSource createDataSource(String url, String username, String password){
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(url);
        config.setUsername(username);
        config.setPassword(password);
        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
        config.setConnectionTimeout(30000); // 设置超时时间为30秒
        config.setMaximumPoolSize(50);
        // config.setLeakDetectionThreshold(300000);
        return new HikariDataSource(config);
    }

}
